/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Telas;

import Entidades.Alunos;
import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.plaf.multi.MultiLookAndFeel;
import javax.swing.table.DefaultTableModel;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

/**
 *
 * @author Roney
 */
public class cadAlunos extends javax.swing.JFrame {
        SessionFactory sesfac = new Configuration().configure().buildSessionFactory();
        List<Alunos> lista_aluno = new ArrayList();
        int posicao_atual = 0;
        int tamanho_lista = 0;
        String listar = "from Alunos order by aluCodigo";
        
    /**
     * Creates new form cadAlunos
     */
    public cadAlunos() {
        initComponents();
        atualizarTabela();
        lookAndFeel();
    }
    
    
    public void lookAndFeel(){
        try{
            UIManager.setLookAndFeel(new WindowsLookAndFeel());
            SwingUtilities.updateComponentTreeUI(this);  
        }
        catch (Exception ex){
            
        }
    }
    
    public void atualizarTabela(){
        
        jtbl_alunos.getColumnModel().getColumn(0).setPreferredWidth(70);
        jtbl_alunos.getColumnModel().getColumn(1).setPreferredWidth(100);
        jtbl_alunos.getColumnModel().getColumn(2).setPreferredWidth(100);
        jtbl_alunos.getColumnModel().getColumn(3).setPreferredWidth(80);
        jtbl_alunos.getColumnModel().getColumn(4).setPreferredWidth(100);
        
        DefaultTableModel dtm = (DefaultTableModel) jtbl_alunos.getModel();
        dtm.setNumRows(0);
        
        try{
            //SessionFactory sesfac = new Configuration().configure().buildSessionFactory();
            Session ses = sesfac.openSession();
            
            //List<Alunos> lista_aluno = new ArrayList();
            lista_aluno = ses.createQuery(listar).list();
            tamanho_lista = lista_aluno.size();
            
            for (int i=0;i<tamanho_lista;i++){
                Alunos alu = lista_aluno.get(i);
                dtm.addRow(new Object[]{alu.getAluCodigo(),
                                        alu.getAluNome(),
                                        alu.getAluCurso(),
                                        alu.getAluFone(),
                                        alu.getAluCidade()}
                        );
                
            }
            if (! lista_aluno.isEmpty()){
                
                posicao_atual = 0;
                Alunos alu = lista_aluno.get(0);
                jtf_codigo.setText(alu.getAluCodigo().toString());
                jtf_nome.setText(alu.getAluNome().toString());
                jtf_curso.setText(alu.getAluCurso().toString());
                jtf_fone.setText(alu.getAluFone().toString());
                jtf_cidade.setText(alu.getAluCidade().toString());
                
                jtbl_alunos.setRowSelectionInterval(0, 0);
            }
            
            
            
            ses.close();
        }
        catch (Exception ex){
            
            JOptionPane.showMessageDialog(null,"Erro ao inserir aluno "+ ex);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jtf_codigo = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jtf_curso = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jtf_nome = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jtf_fone = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jtf_cidade = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jb_novo = new javax.swing.JButton();
        jb_salvar = new javax.swing.JButton();
        jb_excluir = new javax.swing.JButton();
        jb_primeiro = new javax.swing.JButton();
        jb_anterior = new javax.swing.JButton();
        jb_proximo = new javax.swing.JButton();
        jb_ultimo = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtbl_alunos = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jtf_pesquisa = new javax.swing.JTextField();
        jcb_pesquisa = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Codigo.:");

        jtf_codigo.setEditable(false);

        jLabel2.setText("Curso.:");

        jLabel3.setText("Nome.:");

        jLabel4.setText("Fone.:");

        jLabel5.setText("Cidade.:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jtf_cidade, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE)
                            .addComponent(jtf_curso, javax.swing.GroupLayout.Alignment.LEADING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jtf_fone, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jtf_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jtf_nome, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(51, 51, 51)
                                .addComponent(jLabel4))
                            .addComponent(jLabel3))))
                .addContainerGap(187, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtf_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtf_nome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtf_curso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtf_fone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtf_cidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jb_novo.setText("Novo");
        jb_novo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_novoActionPerformed(evt);
            }
        });

        jb_salvar.setText("Salvar");
        jb_salvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_salvarActionPerformed(evt);
            }
        });

        jb_excluir.setText("Excluir");
        jb_excluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_excluirActionPerformed(evt);
            }
        });

        jb_primeiro.setText("|<");
        jb_primeiro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_primeiroActionPerformed(evt);
            }
        });

        jb_anterior.setText("<");
        jb_anterior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_anteriorActionPerformed(evt);
            }
        });

        jb_proximo.setText(">");
        jb_proximo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_proximoActionPerformed(evt);
            }
        });

        jb_ultimo.setText(">|");
        jb_ultimo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_ultimoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jb_novo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jb_salvar)
                .addGap(77, 77, 77)
                .addComponent(jb_excluir)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jb_primeiro)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jb_anterior)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jb_proximo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jb_ultimo)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jb_novo)
                    .addComponent(jb_salvar)
                    .addComponent(jb_excluir)
                    .addComponent(jb_primeiro)
                    .addComponent(jb_anterior)
                    .addComponent(jb_proximo)
                    .addComponent(jb_ultimo))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jtbl_alunos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Codigo", "Nome", "Curso", "Fone", "Cidade"
            }
        ));
        jtbl_alunos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jtbl_alunosMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(jtbl_alunos);

        jLabel6.setText("Pesquisar por.:");

        jcb_pesquisa.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Codigo", "Nome", "Curso", "Fone", "Cidade" }));

        jButton1.setText("Pesquisar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jcb_pesquisa, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(17, 17, 17)
                .addComponent(jtf_pesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtf_pesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jcb_pesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jScrollPane2))
                        .addContainerGap())))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 256, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jtbl_alunosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtbl_alunosMouseClicked
        int linha = jtbl_alunos.getSelectedRow();
        posicao_atual = linha;
        /*jtf_codigo.setText(jtbl_alunos.getValueAt(linha, 0).toString());
        jtf_nome.setText(jtbl_alunos.getValueAt(linha, 1).toString());
        jtf_curso.setText(jtbl_alunos.getValueAt(linha, 2).toString());
        jtf_fone.setText(jtbl_alunos.getValueAt(linha, 3).toString());
        jtf_cidade.setText(jtbl_alunos.getValueAt(linha, 4).toString());*/
        Alunos alu = new Alunos();
        alu.setAluCodigo(Integer.parseInt(jtbl_alunos.getValueAt(linha, 0).toString()));
        alu.setAluNome(jtbl_alunos.getValueAt(linha, 1).toString());
        alu.setAluCurso(jtbl_alunos.getValueAt(linha, 2).toString());
        alu.setAluFone(jtbl_alunos.getValueAt(linha, 3).toString());
        alu.setAluCidade(jtbl_alunos.getValueAt(linha, 4).toString());
        jtf_codigo.setText(alu.getAluCodigo().toString());
        jtf_nome.setText(alu.getAluNome().toString());
        jtf_curso.setText(alu.getAluCurso().toString());
        jtf_fone.setText(alu.getAluFone().toString());
        jtf_cidade.setText(alu.getAluCidade().toString());
    }//GEN-LAST:event_jtbl_alunosMouseClicked

    private void jb_salvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb_salvarActionPerformed
        try{
            //SessionFactory sesfac = new Configuration().configure().buildSessionFactory();
            Session ses = sesfac.openSession();
            
            Alunos alu = new Alunos();
            
            if (! jtf_codigo.getText().equals("")){
                alu.setAluCodigo(Integer.parseInt(jtf_codigo.getText()));
            }
            
            alu.setAluNome(jtf_nome.getText());
            alu.setAluCidade(jtf_cidade.getText());
            alu.setAluCurso(jtf_curso.getText());
            alu.setAluFone(jtf_fone.getText());
            
            Transaction tx = ses.beginTransaction();
            ses.saveOrUpdate(alu);
            tx.commit();
            ses.close();
        }
        catch (Exception ex){
            
            JOptionPane.showMessageDialog(null,"Erro ao inserir aluno "+ ex);
        }
        atualizarTabela();
    }//GEN-LAST:event_jb_salvarActionPerformed

    private void jb_excluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb_excluirActionPerformed
        String excluir = jtf_nome.getText();
        int opcao_escolhida = JOptionPane.showConfirmDialog(null,"Deseja excluir o registro "+excluir+"?","Exclusão ",JOptionPane.YES_NO_OPTION);
        if (opcao_escolhida == JOptionPane.YES_OPTION){
        
        try{
            SessionFactory sesfac = new Configuration().configure().buildSessionFactory();
            Session ses = sesfac.openSession();
            
            Alunos alu = new Alunos();
            alu.setAluCodigo(Integer.parseInt(jtf_codigo.getText()));
                        
            Transaction tx = ses.beginTransaction();
            ses.delete(alu);
            tx.commit();
            ses.close();
            
        }
        catch (Exception ex){
            
            JOptionPane.showMessageDialog(null,"Erro ao excluir aluno "+ ex);
        }
        }
        atualizarTabela();
        
    }//GEN-LAST:event_jb_excluirActionPerformed

    private void jb_proximoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb_proximoActionPerformed
          if (posicao_atual < (tamanho_lista-1)){
                posicao_atual ++;
                Alunos alu = lista_aluno.get(posicao_atual);
                jtf_codigo.setText(alu.getAluCodigo().toString());
                jtf_nome.setText(alu.getAluNome().toString());
                jtf_curso.setText(alu.getAluCurso().toString());
                jtf_fone.setText(alu.getAluFone().toString());
                jtf_cidade.setText(alu.getAluCidade().toString());
                
                jtbl_alunos.setRowSelectionInterval(posicao_atual,posicao_atual);
          }
    }//GEN-LAST:event_jb_proximoActionPerformed

    private void jb_anteriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb_anteriorActionPerformed
        if (posicao_atual > 0){
                posicao_atual --;
                Alunos alu = lista_aluno.get(posicao_atual);
                jtf_codigo.setText(alu.getAluCodigo().toString());
                jtf_nome.setText(alu.getAluNome().toString());
                jtf_curso.setText(alu.getAluCurso().toString());
                jtf_fone.setText(alu.getAluFone().toString());
                jtf_cidade.setText(alu.getAluCidade().toString());
                
                jtbl_alunos.setRowSelectionInterval(posicao_atual,posicao_atual);
          }
    }//GEN-LAST:event_jb_anteriorActionPerformed

    private void jb_ultimoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb_ultimoActionPerformed
                posicao_atual = (tamanho_lista -1);
                Alunos alu = lista_aluno.get(tamanho_lista-1);
                jtf_codigo.setText(alu.getAluCodigo().toString());
                jtf_nome.setText(alu.getAluNome().toString());
                jtf_curso.setText(alu.getAluCurso().toString());
                jtf_fone.setText(alu.getAluFone().toString());
                jtf_cidade.setText(alu.getAluCidade().toString());
          
                jtbl_alunos.setRowSelectionInterval(posicao_atual,posicao_atual);
    }//GEN-LAST:event_jb_ultimoActionPerformed

    private void jb_primeiroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb_primeiroActionPerformed
                posicao_atual = 0;
                Alunos alu = lista_aluno.get(0);
                jtf_codigo.setText(alu.getAluCodigo().toString());
                jtf_nome.setText(alu.getAluNome().toString());
                jtf_curso.setText(alu.getAluCurso().toString());
                jtf_fone.setText(alu.getAluFone().toString());
                jtf_cidade.setText(alu.getAluCidade().toString());
                
                jtbl_alunos.setRowSelectionInterval(posicao_atual,posicao_atual);
    }//GEN-LAST:event_jb_primeiroActionPerformed

    private void jb_novoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb_novoActionPerformed
                jtf_codigo.setText("");
                jtf_nome.setText("");
                jtf_curso.setText("");
                jtf_cidade.setText("");
                jtf_fone.setText("");
                
    }//GEN-LAST:event_jb_novoActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        if (jcb_pesquisa.getSelectedItem().equals("Codigo")){
            listar = "from Alunos where aluCodigo like'%"+jtf_pesquisa.getText()+"%' order by aluCodigo";
            atualizarTabela();
        }
        if (jcb_pesquisa.getSelectedItem().equals("Nome")){
            listar = "from Alunos where aluNome like'%"+jtf_pesquisa.getText()+"%' order by aluNome";
            atualizarTabela();
        }
        if (jcb_pesquisa.getSelectedItem().equals("Curso")){
            listar = "from Alunos where aluCurso like'%"+jtf_pesquisa.getText()+"%' order by aluCurso";
            atualizarTabela();
        }
        if (jcb_pesquisa.getSelectedItem().equals("Fone")){
            listar = "from Alunos where aluFone like'%"+jtf_pesquisa.getText()+"%' order by aluFone";
            atualizarTabela();
        }
        if (jcb_pesquisa.getSelectedItem().equals("Cidade")){
            listar = "from Alunos where aluCidade like'%"+jtf_pesquisa.getText()+"%' order by aluCidade";
            atualizarTabela();
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(cadAlunos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(cadAlunos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(cadAlunos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(cadAlunos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new cadAlunos().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JButton jb_anterior;
    private javax.swing.JButton jb_excluir;
    private javax.swing.JButton jb_novo;
    private javax.swing.JButton jb_primeiro;
    private javax.swing.JButton jb_proximo;
    private javax.swing.JButton jb_salvar;
    private javax.swing.JButton jb_ultimo;
    private javax.swing.JComboBox jcb_pesquisa;
    private javax.swing.JTable jtbl_alunos;
    private javax.swing.JTextField jtf_cidade;
    private javax.swing.JTextField jtf_codigo;
    private javax.swing.JTextField jtf_curso;
    private javax.swing.JTextField jtf_fone;
    private javax.swing.JTextField jtf_nome;
    private javax.swing.JTextField jtf_pesquisa;
    // End of variables declaration//GEN-END:variables
}
